<?php
/**
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * @package Shipping_Agent
 * @copyright Copyright 2010 Structured Solutions
 * @license http://shippingagent.codeplex.com/license MIT License (MIT)
 * @version 3.9
 */

// For debugging/testing purposes we need to turn ON error reporting.
// On default ZenCart installation errors turned OFF and any exception that
// happens on the page gets silently discarded.

error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
//ini_set('display_errors', '1');
ini_set("soap.wsdl_cache_enabled", "0");

/**
 * Load Magento Commerce.
 */
require_once 'app/Mage.php';
Mage::app();

/**
 * Load the SOAP server implementation
 */
$model = Mage::getModel("StructuredSolutions_ShippingAgent_Model_Server");
$server = $model->getSoapServer();

//	echo "=================\n";
//	echo "Supported Functions\n";
//	foreach ($server->getFunctions() as $function)
//		echo "    " . $function . "\n";

/*
 * GetFeatures Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetFeatures xmlns="http://www.codeplex.com/ShippingAgent" />
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetNewOrders Test
 *
 * PageKey has order id and last modified. For example,
 *
 *     <pageKey>1|2009-04-13 14:08:13</pageKey>
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetNewOrders xmlns="http://www.codeplex.com/ShippingAgent">
            <orderStatusList>canceled,closed,complete,holded,pending,pending_amazon_asp,pending_paypal,processing</orderStatusList>
            <paymentStatusList />
			<maxCount>10</maxCount>
            <pageKey>1|2009-04-13 14:08:13</pageKey>
		</GetNewOrders>
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetOrder Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetOrder xmlns="http://www.codeplex.com/ShippingAgent">
			<orderId>2</orderId>
		</GetOrder>
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetOrdersByRange Test
 */

$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetOrdersByRange xmlns="http://www.codeplex.com/ShippingAgent">
            <startOrderNumber />
            <endOrderNumber />
            <orderStatusList>complete,pending,processing</orderStatusList>
            <paymentStatusList />
            <pageKey>12</pageKey>
			<maxCount>5</maxCount>
		</GetOrdersByRange>
	</soap:Body>
</soap:Envelope>
END;


/*
 * GetOrderStatuses Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetOrderStatuses xmlns="http://www.codeplex.com/ShippingAgent" />
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetPackage Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetPackage xmlns="http://www.codeplex.com/ShippingAgent">
			<orderId>2</orderId>
		</GetPackage>
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetPaymentStatuses Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetPaymentStatuses xmlns="http://www.codeplex.com/ShippingAgent" />
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetRateProviders Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetRateProviders xmlns="http://www.codeplex.com/ShippingAgent" />
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetTrackingProviders Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetTrackingProviders xmlns="http://www.codeplex.com/ShippingAgent" />
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * GetVersion Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<GetVersion xmlns="http://www.codeplex.com/ShippingAgent" />
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * SetOrderStatus Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <Credentials xmlns="http://www.codeplex.com/ShippingAgent">
            <Username>admin</Username>
            <Password>password</Password>
        </Credentials>
    </soap:Header>
	<soap:Body>
		<SetOrderStatus xmlns="http://www.codeplex.com/ShippingAgent">
			<orderId>2</orderId>
			<orderStatusId>complete</orderStatusId>
		</SetOrderStatus>
	</soap:Body>
</soap:Envelope>
END;
*/

/*
 * UpdatePackage Test
 */
/*
$HTTP_RAW_POST_DATA = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<UpdatePackage xmlns="http://www.codeplex.com/ShippingAgent">
			<update>
				<Destination>
					<AddressId>d41d8cd98f00b204e9800998ecf8427e</AddressId>
					<FirstName />
					<LastName />
					<Residential>false</Residential>
				</Destination>
				<OrderId>6</OrderId>
				<ShipDate>2009-01-05T00:00:00</ShipDate>
				<PackageId>6</PackageId>
				<ShippingCost>3.0000</ShippingCost>
				<TrackingNumbers>1234</TrackingNumbers>
			</update>
		</UpdatePackage>
	</soap:Body>
</soap:Envelope>
END;
*/

/*
$HTTP_RAW_DATA_POST = <<<END
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<soap:Body>
		<UpdatePackage xmlns="http://www.codeplex.com/ShippingAgent">
			<update>
				<Destination>
					<AddressId>d41d8cd98f00b204e9800998ecf8427e</AddressId>
					<FirstName />
					<LastName />
					<Residential>false</Residential>
				</Destination>
				<OrderId>1</OrderId>
				<PackageId>1</PackageId>
			</update>
		</UpdatePackage>
	</soap:Body>
</soap:Envelope>
END;
*/

	//echo "=================\n";
	$server->handle($HTTP_RAW_POST_DATA);
	//echo "=================\nok\n";

?>